<template>
  <div>
    <el-form ref="ref" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="旧密码" prop="oldpassword">
        <el-input v-model="form.oldpassword"></el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="newpassword">
        <el-input v-model="form.newpassword"></el-input>
      </el-form-item>
      <el-button @click="update1()" size="small" round>修改</el-button>
    </el-form>
  </div>
</template>

<script>
export default {
  // 数据
  data () {
    return {
      form: {
        oldpassword: "",
        newpassword: "",
      },
      rules: {
        oldpassword: [
          { required: true, message: "旧密码是必填的哦", trigger: "blur" },
          { min: 6, max: 12, message: "密码是6-12位哦", trigger: "blur" },
        ],
        newpassword: [
          { required: true, message: "新密码是必填的哦", trigger: "blur" },
          { min: 6, max: 12, message: "密码是6-12位哦", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    update1 () {
      this.$refs.ref.validate(async (valid) => {
        if (!valid) return;
        const res = await this.$http.post(
          "http://127.0.0.1:8080/my/updatePwd",
          this.$qs.stringify(this.form)
        );
        console.log(res.data.status);
        if (res.data.status == 1) return this.$message.error(res.data.message);
        else if (res.data.status == 0) window.sessionStorage.clear;
        this.$router.push("/login");
      });
    },
  },
};
</script>

<style lang="less" scoped>
</style>
